home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / fibstat.c < prev    next >
C/C++ Source or Header  |  1996-11-10  |  1KB  |  48 lines

  1. #include "amiga.h"
  2. #include "timeconvert.h"
  3. #include <fcntl.h>
  4. #include <time.h>
  5. #include <sys/stat.h>
  6.  
  7. void 
  8. _fibstat(struct FileInfoBlock *fib, int isroot, struct stat *sbuf, long dev)
  9. {
  10.     long protection = fib->fib_Protection;
  11.  
  12.     sbuf->st_dev = dev;
  13.     sbuf->st_rdev = 0;
  14.     sbuf->st_uid = AMIGA_UID;
  15.     sbuf->st_gid = AMIGA_GID;
  16.     sbuf->st_blksize = 512;
  17.     sbuf->st_nlink = 1;
  18.     sbuf->st_blocks = fib->fib_NumBlocks;
  19.     /* Give directories an arbitrary size */
  20.     if (fib->fib_Size == 0 && fib->fib_DirEntryType > 0)
  21.     sbuf->st_size = 2048;
  22.     else
  23.     sbuf->st_size = fib->fib_Size;
  24.     sbuf->st_ino = fib->fib_DiskKey;
  25.     sbuf->st_ctime = sbuf->st_atime = sbuf->st_mtime = _amiga2gmt(&fib->fib_Date);
  26.  
  27.     switch (fib->fib_DirEntryType) {
  28.         /*case ST_SOFTLINK: sbuf->st_mode = S_IFLNK; break; */
  29.     case ST_PIPEFILE:
  30.         sbuf->st_mode = S_IFIFO;
  31.         break;
  32.         /* If Examine wasn't braindead this would be the right test */
  33.     case ST_ROOT:
  34.         sbuf->st_mode = S_IFDIR;
  35.         protection = 0;
  36.         break;
  37.     default:
  38.         sbuf->st_mode = fib->fib_DirEntryType > 0 ? S_IFDIR : S_IFREG;
  39.         break;
  40.     }
  41.     /* Examine is braindead. You can't tell if you've examined a root directory
  42.        (for which the protection flags are invalid) or not. */
  43.     if (isroot)
  44.     protection = 0;
  45.  
  46.     sbuf->st_mode |= _make_mode(protection);
  47. }
  48.